package com.xzz.treeBST;

/**
 * @author: hhz
 * @create: 2022-01-20 16:08
 * 108. 将有序数组转换为二叉搜索树
 **/
public class SortedArrayToBST {
    public static void main(String[] args) {
        TreeNode treeNode = sortedArrayToBST(new int[]{-10, -3, 0, 5, 9});
        System.out.println();
    }

    public static TreeNode sortedArrayToBST(int[] nums) {
        return build(nums,0,nums.length-1);
    }
    public static TreeNode build(int[] nums,int left,int right){
        if(left>right){
            return null;
        }
        int mid = left+(right-left)/2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = build(nums,left,mid-1);
        node.right = build(nums,mid+1,right);
        return node;
    }
}
